﻿
using HDLogCenter.Dal.Repos;
using HDLogCenter.Infrastructure.Config;
using HDLogCenter.Infrastructure.ExternalServices;
using HDLogCenter.Infrastructure.Mysql;
using HDLogCenter.Infrastructure.Services;
using HDLogCenterService.JobHandler;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Quartz;

IHost host = Host.CreateDefaultBuilder(args)
    .ConfigureServices((hostContext, services) =>
    {
        IConfiguration configuration = hostContext.Configuration;
        // 配置选项
        services.Configure<MeiliSearchConfig>(configuration.GetSection("MeiliSearchConfig"));
        services.Configure<RMQConsumerConfig>(configuration.GetSection("RabbitMQConsumerConfig"));
        services.Configure<DingTalkConfig>(configuration.GetSection("DingTalkConfig"));

        // 注册服务
        //services.AddScoped<IDbService, DbService>();
        //services.AddScoped<AlertRuleRepo>();
        //services.AddScoped<DingTalkAlertService>();
        services.AddSingleton<RabbitMQService>();
        services.AddSingleton<MeiliSearchService>();
        // services.AddScoped<AlertRuleMonitorService>();
        services.AddSingleton<LogMQMessageHandlerService>();

        // 配置Quartz
        services.AddQuartz(q =>
        {
            // 使用内存存储
            //q.UseInMemoryStore();

            new LogConsumerJobRegister().Register(q);
            
        });
        services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
        // 添加Quartz托管服务
        //services.AddQuartzHostedService(q =>
        //{
        //    var quartzConfig = hostContext.Configuration.GetSection("QuartzConfig").Get<QuartzConfig>() ?? new QuartzConfig();
        //    q.WaitForJobsToComplete = quartzConfig.WaitForJobsToComplete;
        //});
    })
    .Build();

await host.RunAsync();
